use crate::solution::Solution;

impl Solution {
    pub fn min_number_of_hours(initial_energy: i32, mut initial_experience: i32, energy: Vec<i32>, experience: Vec<i32>) -> i32 {
        let (mut min_hours, total_energy) = (0, energy.iter().sum::<i32>());
        min_hours += if total_energy - initial_energy >= 0 { total_energy - initial_energy + 1 } else { 0 };
        for e in experience {
            if initial_experience <= e {
                min_hours += e - initial_experience + 1;
                initial_experience = e + 1;
            }
            initial_experience += e;
        }
        min_hours
    }
}


#[cfg(test)]
mod tests {
    use super::*; // 不加 Solution::识别不了！

    #[test]
    fn test_1() {
        let initial_energy = 5;
        let initial_experience = 3;
        let energy = [1,4,3,2].to_vec();
        let experience = vec![2,6,3,1];
        let expected = 8;

        let ans = Solution::min_number_of_hours(initial_energy, initial_experience, energy, experience);
        println!("{}", ans);
        assert_eq!(ans, expected);
    }
}